%{
    This file is part of StemCellQC, a video bioinformatics software
    toolkit for analysis of phase contrast microscopy videos.
    Copyright 2013-2015 Vincent On. [vincenton001-at-gmail.com]

    StemCellQC is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    StemCellQC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with StemCellQC.  If not, see <http://www.gnu.org/licenses/>.
%}

%function creates bounding_box of a desire size around a specified center
%size = [# of rows, # of columns] in image
%center = [x_cen,y_cen];

function boundary = bounding_box(center ,size, y_length, x_length)

center = round(center);
dy = round(y_length/2);
dx = round(x_length/2);

y_min = center(2) - dy;
y_max = center(2) + dy;
x_min = center(1) - dx;
x_max = center(1) + dx;

if y_min < 1
    y_min = 1;
elseif y_max > size(1)
    y_max = size(1);
elseif x_min < 1
    x_min = 1;
elseif x_max > size(2)
    x_max = size(2);
end

boundary = [y_min, y_max, x_min, x_max];
